-- Decompiled with the Synapse X Luau decompiler.
local ClientOHOH = _G.ClientOHOH;
local function_list = ClientOHOH.function_list;
function_list.player_login = true;
function_list.player_login_over = true;

local M = ClientOHOH.class.new(script, ClientOHOH.files.PlayerObject());
function M.new(p1)
	return M(p1);
end;
function M.ctor(self, player)
	M.super.ctor(self, player);
	--print("C_PPA---Client_PlayerObject>ctor")	

	self:Login();
	--print("C_PPA---Client_PlayerObject>ctor login done")	

end;
function M.dtor(p4)
	M.super.dtor(p4);
end;
local Function_manager = ClientOHOH.function_manager();
local InstanceManager = ClientOHOH.load.InstanceManager();

function M.Login(self)	
	--初始化玩家数据
	--print("C_PPA---Login 0")	

	self.save_data = self:AddComponent(ClientOHOH.load.Client_PlayerDataComponent()); --玩家数据
	local user_data=Function_manager:Invoke(function_list.player_login) --通知服务器登录，获取玩家数据
	self.save_data:SetData(user_data); --设置玩家数据
	--print("C_PPA---Login 2")	

	if self.OnLogin then  --子类调用登录是需要处理的，已有数据
		--print("C_PPA---Login OnLogin")	

		local v3, v4 = xpcall(self.OnLogin, debug.traceback, self);
		if not v3 then
			warn(v4);
		end;
	end;

	--登录完成
	Function_manager:Invoke(function_list.player_login_over); --通知服务器登录完成
	--print("C_PPA---Login player_login_over")	

	if self.OnLoginOver then
		--print("C_PPA---Login self.OnLoginOver")	

		local v5, v6 = xpcall(self.OnLoginOver, debug.traceback, self);
		if not v5 then
			warn(v6);
		end;
	end;
	
	
	--绑定角色被移除事件
	self.main_inst.CharacterRemoving:Connect(function(character)
		--print("C_PPA---CharacterRemoving",character)	
		local characterObj = InstanceManager:FindObject(character);
		self:CharacterOut(characterObj);
	end);
end;
local event_manager = ClientOHOH.event_manager();
function M.Fire(self, msgId, ...)
	event_manager:Fire(msgId, ...);
end;
function M.Invoke(self, fuc, ...)
	return Function_manager:Invoke(fuc, ...);
end;
function M.CharacterIn(self, p12)
	--print("C_PPA---CharacterIn",p12)	

	self.character = p12;
	if self.OnCharacterIn then
		--print("C_PPA---OnCharacterIn",p12)	

		self:AddProcess(self.OnCharacterIn, p12);
	end;
end;
function M.CharacterOut(self, characterObj)
	if characterObj then
		--print("C_PPA---CharacterOut",characterObj)	

		if self.OnCharacterOut then
			--print("C_PPA---OnCharacterOut",characterObj)	

			self:AddProcess(self.OnCharacterOut, characterObj);
		end;
		if self.character == characterObj then
			--print("C_PPA---self.character == characterObj",characterObj)	

			self.character = nil;
		end;
		--print("C_PPA---characterObj.dtor",characterObj)	

		characterObj:AddProcess(characterObj.dtor);
	end
end;

--服务器创建角色模型 监听
event_manager:RegistHandle(ClientOHOH.event_list.server_player_character, function(self, character, characterClass)
	--print("收到服务器的角色创建：",character.Name,characterClass)
	self:CharacterIn((ClientOHOH.load[characterClass]().new(character, self)));
end);

return M;
